
import { on } from '../common/util'

export function initMenu(){

    //菜单
    var menuEl = document.getElementsByClassName('menu')[0];
    if (menuEl) {
        var navEl = document.getElementsByClassName('nav-mb')[0];
        var navLinksEl = navEl.getElementsByClassName('links')[0];
        var navMaskEl = navEl.getElementsByClassName('nav-bg-mask')[0];
        var navCloseEl = navEl.getElementsByClassName('close')[0];
        on(menuEl, ['click'], function () {
            navEl.style.display = 'block';
            setTimeout(function () {
                navLinksEl.style.right = 0;
                navMaskEl.style.opacity = 0.3;
            }, 0);
        });
        function closeMenu() {
            navEl.style.display = '';
            navLinksEl.style.right = '';
            navMaskEl.style.opacity = 0;
        }
        on(navMaskEl, ['click'], closeMenu);
        on(navCloseEl, ['click'], closeMenu);
    }
}